from pydantic_settings import BaseSettings
from typing import Optional


class Settings(BaseSettings):
    # 应用配置
    APP_NAME: str = "小红书AI运营工具"
    VERSION: str = "1.0.0"
    DEBUG: bool = False
    
    # 数据库配置
    DATABASE_URL: str
    
    # 对象存储配置
    STORAGE_PROVIDER: str = "minio"  # minio, s3, oss, cos
    S3_ENDPOINT: str
    S3_ACCESS_KEY: str
    S3_SECRET_KEY: str
    S3_BUCKET: str = "xiaohongshu-posts"
    S3_REGION: str = "us-east-1"
    
    # XXL-Job配置
    XXL_JOB_ADMIN_URL: str
    XXL_JOB_USERNAME: str
    XXL_JOB_PASSWORD: str
    XXL_JOB_EXECUTOR_APP_NAME: str = "xiaohongshu-executor"
    XXL_JOB_EXECUTOR_PORT: int = 9999
    XXL_JOB_EXECUTOR_HOST: str = "host.docker.internal"  # 执行器注册地址
    XXL_JOB_ACCESS_TOKEN: str
    XXL_JOB_AUTO_REGISTRY: bool = True  # 是否启用自动注册
    
    # AI服务配置
    LLM_PROVIDER: str = "openai"  # openai, claude, local
    OPENAI_API_KEY: Optional[str] = None
    OPENAI_BASE_URL: Optional[str] = None
    
    # Playwright配置
    PLAYWRIGHT_HEADLESS: bool = True
    PLAYWRIGHT_TIMEOUT: int = 30000
    
    # 小红书配置
    XIAOHONGSHU_HEADLESS: bool = True
    XIAOHONGSHU_TIMEOUT: int = 30000
    XIAOHONGSHU_USER_DATA_DIR: Optional[str] = None  # 浏览器用户数据目录
    XIAOHONGSHU_AUTO_LOGIN: bool = False  # 是否自动登录
    XIAOHONGSHU_LOGIN_CHECK_INTERVAL: int = 3600  # 登录状态检查间隔（秒）
    XIAOHONGSHU_ACCOUNT_SYNC_INTERVAL: int = 7200  # 账号数据同步间隔（秒）
    
    # 安全配置
    SECRET_KEY: str
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    
    class Config:
        env_file = ".env"
        case_sensitive = True


settings = Settings()